; ORIGINAL: 3dt2.1/examples/apropos.scm
; $Id: apropos.scm,v 1.5 1999/05/28 23:44:57 jmb Exp $
;- apropos.scm ---------------------------------------------------------
; Find scheme procedures whose name includes a given string.
; For example, to find all procedures which include the word "curve"
; issue the command (apropos "curve")
;----------------------------------------------------------------------
(define apropos)

(let ((found))
  (define (got-one sym)
    (if (bound? sym)
        (begin
          (set! found #t)
          (print sym))))
  
  (set! apropos (lambda (what)
                  (if (symbol? what)
                      (set! what (symbol->string what))
                      (if (not (string? what))
                          (error 'apropos "string or symbol expected")))
                  (set! found #f)
                  (do ((tail (oblist) (cdr tail))) ((null? tail))
                      (do ((l (car tail) (cdr l))) ((null? l))
                          (if (substring? what (symbol->string (car l)))
                              (got-one (car l)))))
                  (if (not found)
                      (format #t "~a: nothing appropriate~%" what))
                  #v)))

; Again, but for the option:list instead of oblist
(define o-apropos)

(let ((found))
  (define (got-one sym)
    (begin
      (set! found #t)
      (print sym)))
  
  (set! o-apropos (lambda (what)
                    (if (symbol? what)
                        (set! what (symbol->string what))
                        (if (not (string? what))
                            (error 'o-apropos "string or symbol expected")))
                    (set! found #f)
                    (do ((tail (option:list) (cdr tail))) ((null? tail))
                        (if (substring? what (caar tail))
                            (got-one (car tail))))
                    (if (not found)
                        (format #t "~a: nothing appropriate~%" what))
                    #v)))
